package com.woniuxy.stage3demo.service.kang.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.stage3demo.bean.kang.CousBean;
import com.woniuxy.stage3demo.mapper.kang.CousMapper;
import com.woniuxy.stage3demo.pageHelper.PageRequest;
import com.woniuxy.stage3demo.service.kang.ICousService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
@Transactional(readOnly = true)
public class CousServiceImpl implements ICousService {

    @Resource
    private CousMapper cousMapper;

    @Override
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    public void addCous(CousBean cousBean) {
        cousMapper.addCous(cousBean);
    }

    @Override
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    public int deleteCous(Long id) {
        return cousMapper.deleteCous(id);
    }

    @Override
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    public void updateCous(CousBean cousBean) {
        cousMapper.updateCous(cousBean);
    }

    @Override
    public PageInfo<CousBean> findLimit(PageRequest pageRequest, CousBean cousBean) {
        return PageHelper.startPage(pageRequest.getPageNum(),pageRequest.getLimit()).doSelectPageInfo(()->cousMapper.findLimit(pageRequest,cousBean));
    }
}
